package cn.com.nes.site.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
@Configuration
public class SwaggerConfig {


    @Bean
    public Docket apiV2() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiV2Info())
                .groupName("API-V2")
                .select()
                //自定义需要扫描的路径
                // .apis(RequestHandlerSelectors.any()) // 全部
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) // 指定特殊方法注解的
                // .apis(RequestHandlerSelectors.basePackage("cn.com.nes.site.controller")) // 指定包路径下
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiV2Info() {
        return new ApiInfoBuilder()
                .title("热链云API文档-V2")
                // .description("规范、整合API文档记录，方便API统一管理！")
                // 将“url”换成自己的ip:port
                // .termsOfServiceUrl("http://127.0.0.1:8081/AgentPlatform/swagger-ui.html")
                // .contact(new Contact("yis", "yis@nes.com.cn", "yis@nes.com.cn"))
                .version("2.0")
                .build();
    }

    @Bean
    public Docket apiV1() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiV1Info())
                .groupName("API-V1")
                .select()
                //自定义需要扫描的路径
                // .apis(RequestHandlerSelectors.any()) // 全部
                // .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)) // 指定特殊方法注解的
                .apis(RequestHandlerSelectors.basePackage("cn.com.nes.site.action")) // 指定包路径下
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiV1Info() {
        return new ApiInfoBuilder()
                .title("热链云API文档-V1")
                // .description("规范、整合API文档记录，方便API统一管理！")
                // 将“url”换成自己的ip:port
                // .termsOfServiceUrl("http://127.0.0.1:8081/AgentPlatform/swagger-ui.html")
                // .contact(new Contact("yis", "yis@nes.com.cn", "yis@nes.com.cn"))
                .version("1.0")
                .build();
    }

}
